home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
doorskl3.arc
/
DOORMISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-15
|
11KB
|
459 lines
/**********************************************/
/* */
/* XBBS Door Skeleton -- TC 2.0/MSC 6.0a code */
/* Copyright (c) 1990/91 by M. Kimes */
/* All Rights Reserved */
/* May be freely used for >>>FREE<<< programs */
/* as long as you don't try to save any souls */
/* (nasty habit) */
/* */
/**********************************************/
/* Always include this module (with appropriate #defines) */
/* Miscellaneous junk this module */
/**************************************************************************
Miscellaneous notes:
#define XBBS and the program will be compiled to read ONLINE.XBS
#define DORINFO and the program will be compiled to read DORINFO?.DEF
#define both and first ONLINE.XBS will be read, then DORINFO?.DEF
(don't know why you'd wanna do that)
#define neither and all info must come from command line
#define FINDUSER and a routine to find a given user (by name) will
be compiled in (finduser()) for XBBS' USERS.BBS
#define NOREADFILE and the file reader routine (readtext()) will NOT
be compiled
#define DISABLEBREAK to disable CTRL-BREAK/CTRL-C
#define DIALTRANS to include code for sending modem control strings
set chars to be unsigned by default
recommend large model (recompile screen2.asm and ansi.asm if other)
this code requires a FOSSIL for serial i/o--see function fossil()
***************************************************************************/
#include "doorskel.h" /* XBBS include file */
char * _fastcall addtolog (char *text) { /* write entries to logfile */
FILE *pf;
char p[127];
pf = fopen(logfile,"a");
if (pf == NULL) return text;
fseek(pf,0,SEEK_END);
if (text[0] != '*') {
strcpy(p,fidodate());
p[16] = 0;
strcat(p," ");
strncat(p,text,126 - strlen(p));
p[126] = 0;
}
else {
strncpy(p,text,79);
p[79] = 0;
}
fputs(p,pf);
fputs("\n",pf);
fclose(pf);
return text;
}
/* Position cursor */
void _fastcall cursor (int x, int y) {
#ifndef __TURBOC__
union REGS rg;
#endif
x--;
y--;
#ifndef __TURBOC__
rg.x.ax = 0x0200;
rg.x.bx = 0;
rg.x.dx = ((y << 8) & 0xff00) + x;
int86(0x10,&rg,&rg);
#else
_AX = 0x0200;
_BX = 0;
_DX = ((y << 8) & 0xff00) + x;
geninterrupt(0x10);
#endif
}
/* Return cursor position */
void _fastcall curr_cursor (int *x,int *y) {
#ifndef __TURBOC__
union REGS rg;
rg.x.ax = 0x0300;
rg.x.bx = 0;
int86(0x10,&rg,&rg);
*x = rg.h.dl + 1;
*y = rg.h.dh + 1;
#else
_AX = 0x0300;
_BX = 0;
geninterrupt(0x10);
*x = _DL + 1;
*y = _DH + 1;
#endif
}
/* insensitive strstr() */
char * _fastcall stristr (char *t, char *s) {
char *t1;
char *s1;
while(*t) {
t1=t;
s1=s;
while(*s1) {
if (toupper(*s1)!=toupper(*t)) break;
else {
s1++;
t++;
}
}
if (!*s1) return t1;
t=t1+1;
}
return NULL;
}
char * _fastcall stripcr (char *a) { /* Strips trailing CR's & LF's */
while (a[strlen(a)-1]=='\n' || a[strlen(a)-1]=='\r') a[strlen(a)-1]=0;
return a;
}
char * _fastcall lstrip (char *a) { /* Strips leading blanks */
while (*a == ' ') memmove (a,(a + 1),strlen(a));
return (a);
}
char * _fastcall rstrip (char *a) { /* Strips trailing blanks */
while (*a && a[strlen(a) - 1] == ' ') a[strlen(a) - 1] = 0;
return a;
}
char _fastcall spawnit (char *strr) {
/* Use this function to spawn external programs (like file transfer
protocols, archivers, etc.) Just pass the string as you would
to system() except remember that it doesn't go through the
command processor (i.e. spawnit(getenv("COMSPEC")); not just
spawnit(""); ). It'll clear the screen, run the program, then
return you to the appropriate drive and directory and redraw
the screen. For a function that will swap to EMS or disk, I
direct you to the XBBS or HeadEdit source, or shop around for
one of those fancy packages they have now for XMS/EMS/disk
swapping and plug it in. */
char *e[26];
static char a[256];
register word x;
int level = 0;
union REGS r;
char middle[MAXDIR+2];
word drive;
#ifndef __TURBOC__
word temp;
#endif
char dir[MAXDIR];
if(!strr || !*strr) return (char)(level = 1);
set_cooked();
#ifndef __TURBOC__
_dos_getdrive(&drive);
getcwd(dir,MAXDIR);
#else
drive=getdisk();
getcurdir(++drive,dir);
#endif
fossil(DEINIT,0);
fputs("\n\x1b[2J",stdout);
if(strr == getenv("COMSPEC")) {
fputs("EXIT to return to Door\n",stdout);
}
strcpy(a,strr);
for (x=0;x<26;x++) e[x]=NULL;
e[0]=strtok(a," ");
for (x = 1;(e[x] = strtok(0," "));x++) if (x == 25) break;
level = (int)spawnvp(P_WAIT,a,e);
fossil(INIT,0);
#ifndef __TURBOC__
_dos_setdrive (drive,&temp);
#else
setdisk (--drive);
#endif
strcpy(middle,"\\");
strcat(middle,dir);
chdir(middle);
if (!level) {
r.h.ah=77;
int86(33,&r,&r);
level=(int)r.h.al;
}
set_raw();
fputs("\x1b[2J\x1b[0m",stdout);
print_stat();
return (char)level;
}
void _fastcall set_screen_size (void) {
union REGS r;
r.h.ah = 0x0f; /* set maxx and maxy globals to screen size */
int86(0x10,&r,&r); /* this is called for you in DOORSKEL.C's main () */
if (maxx == 0)
maxx = (int) r.h.ah;
if (maxy == 0) {
r.x.ax = 0x1130;
r.x.dx = maxy;
int86(0x10,&r,&r);
maxy = (r.x.dx == 0) ? 25 : (r.x.dx + 1); /* kludge, kludge, kludge */
}
}
void _fastcall set_cooked (void) {
union REGS rg;
rg.x.ax = 0x4400; /* Set console in (std) cooked mode */
rg.x.bx = 1;
int86(33,&rg,&rg);
rg.h.dh = 0;
rg.h.dl = rg.h.dl & (char)(~0x20);
rg.x.ax = 0x4401;
int86(33,&rg,&rg);
}
void _fastcall set_raw (void) {
union REGS r;
r.h.ah = 0x33;
r.h.al = 0x01;
r.h.dl = 0x00;
int86(0x21,&r,&r); /* turn ctrl-break flag off */
r.x.ax = 0x4400;
r.x.bx = 1;
int86(0x21,&r,&r);
r.h.dh = 0;
r.h.dl = r.h.dl | 0x20;
r.x.ax = 0x4401;
int86(0x21,&r,&r); /* set console in raw mode */
}
#ifndef __TURBOC__
char *searchpath (char *filename) {
static char fbuf[153];
struct stat st;
char *envbuf = NULL,*p,temp;
p = getenv("PATH");
if(!p) return filename;
envbuf = strdup(p);
if(!envbuf) return filename;
p = strtok(envbuf,";");
do {
strncpy(fbuf,p,128);
fbuf[128] = 0;
temp = fbuf[strlen(fbuf) - 1];
if(temp != '/' && temp != '\\') strcat(fbuf,"\\");
strcat(fbuf,filename);
if(!stat(fbuf,&st)) {
if(envbuf) free(envbuf);
return fbuf;
}
p = strtok(0,";");
} while(p);
if(envbuf) free(envbuf);
return NULL;
}
#endif
/* Return video mode (B/W or color) */
int _fastcall vmode () {
union REGS rg;
rg.h.ah = 15;
int86(16,&rg,&rg);
return rg.h.al;
}
#ifdef DIALTRANS
int _fastcall dial_trans (char *s) {
/* send chars to the modem with translation for ^v~| */
/* this won't be needed in a "normal" Door. see also
/* macros SendByte and CSendByte. Note no carrier check
/* (obviously). */
char *p = s;
while(p && *p) {
switch(*p) {
case '~':
/* ~ = 1 second delay */
my_sleep(1);
break;
case '`':
{
/* ` = .1 second delay */
clock_t t;
t = timerset(100L);
while(!timeup(t)) {
pause_mtask();
}
}
break;
case '^':
/* ^ = dtr up */
fossil(DTR,UP);
break;
case 'v':
/* v = dtr down */
fossil(DTR,DOWN);
break;
case '|':
/* | = carriage return */
while(!fossil(TRANSMIT,'\r'));
break;
default:
/* else send it */
while(!fossil(TRANSMIT,*p));
}
p++;
}
return 0;
}
int _fastcall recvbyte (void) { /* note: normally you'd use inkey()
to get a keypress. this is for
special purposes not usually
encountered in a door. note
there's no carrier check in this
one. */
union REGS rg;
rg.x.dx = commport;
rg.h.ah = GETSTAT;
int86(20,&rg,&rg);
if (!(rg.h.ah & 1)) return -1; /* no char available */
return (int)fossil(RECVWAIT,0);
}
int _fastcall is_carrier (void) { /* note: carrier check is already
implemented in the normal door
routines. this is for special
purposes not usually encountered
in a door */
union REGS rg;
rg.x.dx = commport;
rg.h.ah = GETSTAT;
int86(20,&rg,&rg);
if (!(rg.h.al & 128)) return 0; /* no carrier */
return -1;
}
char * _fastcall get_modemstring (clock_t timer) {
/* gets a cr-terminated string
from the modem (usually a
result string) within timer
milliseconds */
clock_t t1;
static char str[81];
register int y = 0;
int c;
*str = 0; /* initialize string */
t1 = timerset(timer); /* initialize timer */
while(!timeup(t1)) {
c = recvbyte();
switch(c) {
case -1; /* got nothing */
pause_mtask();
break;
case '\r':
return str; /* got it all */
default:
str[y++] = (char)c;
str[y] = 0;
if(y > 79) return str; /* max length */
}
}
return str; /* timeout if we get here */
}
#endif